﻿using LibraryProject.Model;
using LibraryProject.Tool;
using SQLite;

namespace LibraryProject.Service.Implement;

public class AccountService : IAccountService {

    // 获取数据库链接
    private SQLiteAsyncConnection Connection =>
        SqLiteConnectionPro.Connection;

    // 创建表
    public async Task<int> CreateTable() {
        return await SqLiteConnectionPro.CreateTable<Account>("account");
    }

    // 初始化表
    public async Task InitTable(string accountId, string deviceId) {
        await CreateTable();
        var account = new Account() { AccountId = accountId, DeviceId = deviceId };
        await Connection.InsertAsync(account);
    }

    //  查找数据
    public async Task<Account> QueryData() {
        return await Connection.Table<Account>().FirstOrDefaultAsync();
    }
}